<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Blackdomains extends Model
{
    protected $table = 'black_domains';
    protected $primaryKey = 'id';

    public static function getBlackDetail($domain)
    {
        return self::where("domain",$domain)->where("disable",1)->first();
    }

    public static function getBlackLists($name,$domain)
    {
        $query = self::query();
        if (!empty($name)) $query->where("name",$name);
        if (!empty($domain)) $query->where("domain",$domain);
        return $query->paginate(25);
    }

    public static function addBlack($name,$domain)
    {
        return self::insertGetId(["name"=>$name,"domain"=>$domain,"created_at"=>time()]);
    }

    public static function updateBlack($id,$name,$domain)
    {
        return self::where("id",$id)->update(["name"=>$name,"domain"=>$domain]);
    }

    public static function deleteBlack($id)
    {
        return self::where("id",$id)->delete();
    }
}
